﻿@using Webdiyer.WebControls.Mvc
@using HuntingFishGame.ManageDomain.Model.WeChat;
@model PagedList<AutoReplyModel>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
    Dictionary<string, string> stateDic = ViewBag.StateList as Dictionary<string, string>;
}
<div class="head">
    <div class="title">
        自动回复消息列表
    </div>
</div>
<div class="orderlist m10 myorder">
    @using (Html.BeginForm("Index", "AutoReply", FormMethod.Get))
    {
        <div class="item_list pt10">
            <div class="item_list">
                <ul>
                    <li>
                        <label>是否冻结：</label>
                        <select name="sfdj">
                            <option value="">请选择</option>
                            @{
        foreach (KeyValuePair<string, string> k in stateDic)
        {
            <option value="@k.Key" @Html.Raw(k.Key == ViewBag.sfdj ? "selected=selected" : "")>@k.Value</option>
        }
                            }
                        </select>
                    </li>
                    <li>
                        <label>关键字</label>
                        <input type="text" name="keyword" value="@(string.IsNullOrEmpty(ViewBag.keyword) ? "" : ViewBag.keyword)" />
                    </li>
                    <li>
                        <label>创建时间</label><input type="text" class="text" autocomplete="off" name="CStime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'1900-01-01',readOnly:true})" value="@(string.IsNullOrEmpty(ViewBag.CStime) ? "" : ViewBag.CStime)" />
                        至
                        <input type="text" class="text" autocomplete="off" name="CEtime" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'1900-01-01',readOnly:true})" value="@(string.IsNullOrEmpty(ViewBag.CEtime) ? "" : ViewBag.CEtime)" />
                    </li>

                    <li class="search">
                        <input type="submit" class="btn1" value="搜索" accesskey="S" />
                    </li>
                </ul>
            </div>
        </div>
    }
    <div class="tab_cont">
        <a class="btn1" href="@Url.Action("AddOrEdit", "AutoReply")">新增</a>
        <div id="tradelist" class="list">
            <table>
                <tr>
                    <th>id</th>
                    <th>关键词</th>
                    <th style="width: 300px;">自动回复内容</th>
                    <th>状态</th>
                    <th>创建时间</th>
                    <th style="width: 100px">操作</th>
                </tr>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>@item.id</td>
                        <td>@item.keyword</td>
                        <td style="word-break: break-all; text-align: left; vertical-align: top;">@item.content</td>
                        <td>@(item.sfdj==true?"禁用":"启用")</td>
                        <td>@item.createtime</td>
                        <td>
                            <p><a class="btn1" href="@Url.Action("AddOrEdit", "AutoReply", new { id = @item.id })">修改</a></p>
                            <p><a class="btn1" href="javascript:void(0)" onclick="UpdateState('@item.id','@(item.sfdj == true ? "false" : "true")')">@(item.sfdj == true ? "启用自动回复" : "禁用自动回复")</a></p>
                            <p><a class="btn1" href="javascript:void(0)" onclick="Delete('@item.id')" target="_blank">删除</a></p>
                        </td>
                    </tr>
                }
            </table>
            <div class="total pt10">
                <div class="fl">共<em>@Model.TotalPageCount</em>页<em>@Model.TotalItemCount</em>条记录，当前为第<em>@Model.CurrentPageIndex</em>页</div>
                @Html.Pager(Model, new PagerOptions { PageIndexParameterName = "pageIndex", ShowPageIndexBox = true, PageIndexBoxType = PageIndexBoxType.TextBox, CssClass = "mvcPager" }, new MvcAjaxOptions { UpdateTargetId = "searchForm" })
            </div>
        </div>
    </div>
</div>
<script>
    function UpdateState(id, sfdj) {
        $.ajax({
            url: '@Url.Action("UpdateState", "AutoReply")',
            type: "post",
            //contentType: "application/json",
            //dataType: 'json',
            data: {
                id: id,
                sfdj: sfdj
            },
            success: function (data) {
                if (data.code > 0) {
                    alert("操作成功！");
                    window.location.reload();
                }
                else {
                    alert(data.msg);
                }
            }
        })
    }
    function Delete(id) {
        if (confirm("确定要删除数据吗？")) {
            $.ajax({
                url: '@Url.Action("Delete", "AutoReply")',
                type: "post",
                data: {
                    id: id
                },
                success: function (data) {
                    if (data.code > 0) {
                        alert("删除成功！");
                        window.location.reload();
                    }
                    else {
                        alert(data.msg);
                    }
                }
            })
        }
    }
</script>
